package com.huanhong.hik.service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.net.NetUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.huanhong.hik.bean.AccessControl;
import com.huanhong.hik.bean.Plan;
import com.huanhong.hik.service.impl.AccessControlServiceImpl;
import com.huanhong.hik.util.HCNetSDK;
import com.huanhong.hik.util.callback.*;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;

/**
 * 门禁设备抽象实现
 *
 * @author zhls1
 */
@Slf4j
@Data
public abstract class AbstractAccessControlService implements DeviceService {
    /**
     * 门禁
     */
    private AccessControl accessControl = new AccessControl();

    @Override
    public long login(String ip, int port, String username, String password) {
        if (StrUtil.isEmpty(ip) || StrUtil.isEmpty(username) || StrUtil.isEmpty(password) || port < 1000) {
            return -1;
        }
        //注册之前先注销已注册的用户,预览情况下不可注销
        if (this.accessControl.getUserId() > -1) {
            //先注销
            this.accessControl.getHCNetSDK().NET_DVR_Logout(new NativeLong(this.accessControl.getUserId()));
            this.accessControl.setUserId(-1);
        }
        // 设备信息
        HCNetSDK.NET_DVR_DEVICEINFO_V30 mStrDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
        long userId = this.accessControl.getHCNetSDK().NET_DVR_Login_V30(ip, (short) port, username, password, mStrDeviceInfo).longValue();
        if (userId < 0) {
            log.info("登录失败：" + this.accessControl.getHCNetSDK().NET_DVR_GetLastError());
        }
        this.accessControl.setUserId(userId);
        return this.accessControl.getUserId();
    }

    @Override
    public void logout() {
        //报警撤防
        if (this.accessControl.getLAlarmHandle() > -1) {
            if (this.accessControl.getHCNetSDK().NET_DVR_CloseAlarmChan_V30(new NativeLong(this.accessControl.getLAlarmHandle()))) {
                log.info("撤防成功");
                this.accessControl.setLAlarmHandle(-1);
            }
        }
        //注销
        if (this.accessControl.getUserId() > -1) {
            if (this.accessControl.getHCNetSDK().NET_DVR_Logout(new NativeLong(this.accessControl.getUserId()))) {
                log.info("注销成功");
                this.accessControl.setUserId(-1);
            }
        }
    }

    @Override
    public HCNetSDK.NET_DVR_NETCFG_V30 getNetwork() {
        HCNetSDK.NET_DVR_NETCFG_V30 mStrNetConfig = new HCNetSDK.NET_DVR_NETCFG_V30();
        IntByReference ibrBytesReturned = new IntByReference(0);
        mStrNetConfig.write();
        Pointer lpNetConfig = mStrNetConfig.getPointer();
        boolean getDVRConfigSuc = this.accessControl.getHCNetSDK().NET_DVR_GetDVRConfig(new NativeLong(this.accessControl.getUserId()), HCNetSDK.NET_DVR_GET_NETCFG_V30,
                new NativeLong(0), lpNetConfig, mStrNetConfig.size(), ibrBytesReturned);
        mStrNetConfig.read();
        this.accessControl.setMStrNetConfig(mStrNetConfig);
        return mStrNetConfig;
    }

    @Override
    public HCNetSDK.NET_DVR_DEVICECFG_V40 getDeviceConfig() {
        HCNetSDK.NET_DVR_DEVICECFG_V40 devicecfg = new HCNetSDK.NET_DVR_DEVICECFG_V40();
        IntByReference ibrBytesReturned = new IntByReference(0);
        devicecfg.write();
        Pointer lpNetConfig = devicecfg.getPointer();
        boolean getDVRConfigSuc = this.accessControl.getHCNetSDK().NET_DVR_GetDVRConfig(new NativeLong(this.accessControl.getUserId()),
                HCNetSDK.NET_DVR_GET_DEVICECFG_V40, new NativeLong(0), lpNetConfig, devicecfg.size(), ibrBytesReturned);
        if (!getDVRConfigSuc) {
            int iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("获取设备的配置信息失败，错误号：{}", iErr);
            return devicecfg;
        }
        devicecfg.read();
        this.accessControl.setDevicecfg(devicecfg);
        return devicecfg;
    }

    @Override
    public boolean setNetwork(HCNetSDK.NET_DVR_NETCFG_V30 mStrNetConfig) {
        if (null == mStrNetConfig) {
            return false;
        }
        mStrNetConfig.write();
        Pointer lpNetConfig = mStrNetConfig.getPointer();
        boolean setDVRConfigSuc = this.accessControl.getHCNetSDK().NET_DVR_SetDVRConfig(new NativeLong(this.accessControl.getUserId()), HCNetSDK.NET_DVR_SET_NETCFG_V30,
                new NativeLong(0), lpNetConfig, mStrNetConfig.size());
        mStrNetConfig.read();
        return setDVRConfigSuc;
    }

    @Override
    public boolean setNetwork(String alarmIp, int port) {
        if (null == this.accessControl.getMStrNetConfig()) {
            log.error("请先获取网络状态！");
            return false;
        }
        this.accessControl.getMStrNetConfig().struAlarmHostIpAddr.sIpV4 = alarmIp.getBytes();
        this.accessControl.getMStrNetConfig().wAlarmHostIpPort = (short) port;
        return setNetwork(this.accessControl.getMStrNetConfig());
    }

    @Override
    public long startAlarmListen(String ip, int port) {
        if (StrUtil.isEmpty(ip)) {
            ip = NetUtil.getLocalhostStr();
        }
        if (port < 1000) {
            port = 7200;
        }
        Pointer pUser = null;
        if (null == this.accessControl.getFMSFCallBack()) {
            this.accessControl.setFMSFCallBack(new FMSGCallBack());
        }
        NativeLong lListenHandle = this.accessControl.getHCNetSDK().NET_DVR_StartListen_V30(ip, (short) port, this.accessControl.getFMSFCallBack(), pUser);
        this.accessControl.setListenHandle(lListenHandle.longValue());
        return this.accessControl.getListenHandle();
    }

    @Override
    public boolean stopAlarmListen() {
        if (this.accessControl.getListenHandle() < 0) {
            return true;
        }
        return this.accessControl.getHCNetSDK().NET_DVR_StopListen_V30(new NativeLong(this.accessControl.getListenHandle()));
    }

    @Override
    public void getAllCard() {
        int iErr = 0;
        HCNetSDK.NET_DVR_CARD_CFG_COND mStruCardInputParam = new HCNetSDK.NET_DVR_CARD_CFG_COND();
        mStruCardInputParam.dwSize = mStruCardInputParam.size();
        //查找全部
        mStruCardInputParam.dwCardNum = 0xffffffff;
        mStruCardInputParam.byCheckCardNo = 1;

        Pointer lpInBuffer = mStruCardInputParam.getPointer();
        Pointer pUserData = null;
        this.accessControl.setFRemoteCfgCallBackCardGet(new FRemoteCfgCallBackCardGet("getAllCard"));
        mStruCardInputParam.write();

        NativeLong lHandle = this.accessControl.getHCNetSDK().NET_DVR_StartRemoteConfig(new NativeLong(this.accessControl.getUserId()), HCNetSDK.NET_DVR_GET_CARD_CFG_V50, lpInBuffer, mStruCardInputParam.size(), this.accessControl.getFRemoteCfgCallBackCardGet(), pUserData);
        if (stopRemoteConfig(lHandle)) {
            return;
        }
        log.info("断开长连接成功");
    }

    @Override
    public void getCard(String cardNo) {
        int iErr = 0;
        HCNetSDK.NET_DVR_CARD_CFG_COND mStruCardInputParam = new HCNetSDK.NET_DVR_CARD_CFG_COND();
        mStruCardInputParam.dwSize = mStruCardInputParam.size();
        //查找全部
        mStruCardInputParam.dwCardNum = 1;
        mStruCardInputParam.byCheckCardNo = 1;

        Pointer lpInBuffer = mStruCardInputParam.getPointer();
        Pointer pUserData = null;
        this.accessControl.setFRemoteCfgCallBackCardGet(new FRemoteCfgCallBackCardGet("getCard"));
        mStruCardInputParam.write();

        NativeLong lHandle = this.accessControl.getHCNetSDK().NET_DVR_StartRemoteConfig(new NativeLong(this.accessControl.getUserId()), HCNetSDK.NET_DVR_GET_CARD_CFG_V50, lpInBuffer, mStruCardInputParam.size(), this.accessControl.getFRemoteCfgCallBackCardGet(), pUserData);
        if (lHandle.intValue() < 0) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("建立长连接失败，错误号：{}", iErr);
            return;
        }

        //查找指定卡号
        HCNetSDK.NET_DVR_CARD_CFG_SEND_DATA mStruCardSendInputParam = new HCNetSDK.NET_DVR_CARD_CFG_SEND_DATA();
        mStruCardSendInputParam.read();
        mStruCardSendInputParam.dwSize = mStruCardSendInputParam.size();
        mStruCardSendInputParam.byCardNo = cardNo.getBytes();
        mStruCardSendInputParam.byRes = "0".getBytes();

        Pointer pSendBuf = mStruCardSendInputParam.getPointer();
        mStruCardSendInputParam.write();

        if (!this.accessControl.getHCNetSDK().NET_DVR_SendRemoteConfig(lHandle, 0x3, pSendBuf, mStruCardSendInputParam.size())) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("ENUM_ACS_SEND_DATA失败，错误号：{}", iErr);
            return;

        }
        if (stopRemoteConfig(lHandle)) {
            return;
        }
        log.info("断开长连接成功");
    }

    @Override
    public void setCard(String cardNo, int cardValid, String validBeginTime, String validEndTime, int cardType,
                        String doorRight, int leaderCard, int employeeNo, String name, String password) {
        int iErr;
        //设置卡参数
        HCNetSDK.NET_DVR_CARD_CFG_COND mStruCardInputParamSet = new HCNetSDK.NET_DVR_CARD_CFG_COND();
        mStruCardInputParamSet.read();
        mStruCardInputParamSet.dwSize = mStruCardInputParamSet.size();
        mStruCardInputParamSet.dwCardNum = 1;
        mStruCardInputParamSet.byCheckCardNo = 1;
        Pointer lpInBuffer = mStruCardInputParamSet.getPointer();
        mStruCardInputParamSet.write();

        Pointer pUserData = null;
        if (null == this.accessControl.getFRemoteCfgCallBackCardSet()) {
            this.accessControl.setFRemoteCfgCallBackCardSet(new FRemoteCfgCallBackCardSet());
        }

        NativeLong lHandle = this.accessControl.getHCNetSDK().NET_DVR_StartRemoteConfig(new NativeLong(this.accessControl.getUserId()),
                HCNetSDK.NET_DVR_SET_CARD_CFG_V50, lpInBuffer, mStruCardInputParamSet.size(), this.accessControl.getFRemoteCfgCallBackCardSet(), pUserData);
        if (lHandle.intValue() < 0) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.error("建立长连接失败，错误号：{}", iErr);
            return;
        }
        log.info("建立设置卡参数长连接成功!");
        //卡参数
        HCNetSDK.NET_DVR_CARD_CFG_V50 struCardInfo = new HCNetSDK.NET_DVR_CARD_CFG_V50();
        struCardInfo.read();
        struCardInfo.dwSize = struCardInfo.size();
        struCardInfo.dwModifyParamType = 0x00000FFF;

        System.arraycopy(cardNo.getBytes(), 0, struCardInfo.byCardNo, 0, cardNo.length());

        // 卡是否有效：0- 无效，1- 有效（用于删除卡，设置时置为0进行删除，获取时此字段始终为1）
        struCardInfo.byCardValid = (byte) cardValid;
        // 卡类型：1- 普通卡（默认），2- 残疾人卡，3- 黑名单卡，4- 巡更卡，5- 胁迫卡，6- 超级卡，7- 来宾卡，8- 解除卡，9- 员工卡，10- 应急卡，11- 应急管理卡（用于授权临时卡权限，本身不能开门），默认普通卡
        struCardInfo.byCardType = (byte) cardType;
        // 是否为首卡：1- 是，0- 否
        struCardInfo.byLeaderCard = (byte) leaderCard;
        //门1有权限

        JSONUtil.parseObj(doorRight).forEach((k, v) -> {
            int kTemp = Convert.toInt(k);
            struCardInfo.byDoorRight[kTemp] = 1;
            Short[] vTemp = Convert.toShortArray(v);
            for (int i = 0; i < vTemp.length; i++) {
                struCardInfo.wCardRightPlan[kTemp].wRightPlan[i] = vTemp[i];
            }
        });
        //byBelongGroup[0]~byBelongGroup[127]对应群组 1-128，值：1-属于，0-不属于
        struCardInfo.byBelongGroup[0] = 1;
        //卡有效期
        struCardInfo.struValid.byEnable = (byte) cardValid;
        DateTime beginTime = DateUtil.parse(validBeginTime, "yyyy-MM-dd HH:mm:ss");
        struCardInfo.struValid.struBeginTime.wYear = (short) beginTime.year();
        struCardInfo.struValid.struBeginTime.byMonth = (byte) beginTime.monthStartFromOne();
        struCardInfo.struValid.struBeginTime.byDay = (byte) beginTime.dayOfMonth();
        struCardInfo.struValid.struBeginTime.byHour = (byte) beginTime.hour(true);
        struCardInfo.struValid.struBeginTime.byMinute = (byte) beginTime.minute();
        struCardInfo.struValid.struBeginTime.bySecond = (byte) beginTime.second();
        DateTime endTime = DateUtil.parse(validEndTime, "yyyy-MM-dd HH:mm:ss");
        struCardInfo.struValid.struEndTime.wYear = (short) endTime.year();
        struCardInfo.struValid.struEndTime.byMonth = (byte) endTime.monthStartFromOne();
        struCardInfo.struValid.struEndTime.byDay = (byte) endTime.dayOfMonth();
        struCardInfo.struValid.struEndTime.byHour = (byte) endTime.hour(true);
        struCardInfo.struValid.struEndTime.byMinute = (byte) endTime.minute();
        struCardInfo.struValid.struEndTime.bySecond = (byte) endTime.second();
        //无次数限制
        struCardInfo.dwMaxSwipeTime = 0;
        //已刷卡次数
        struCardInfo.dwSwipeTime = 0;
        struCardInfo.byCardPassword = password.getBytes();
        // 工号（用户ID）
        struCardInfo.dwEmployeeNo = employeeNo;
//        // 计划模板(每天)各时间段是否启用，按位表示，0--不启用，1-启用
        struCardInfo.dwPlanTemplate = 0;

        struCardInfo.byRightType = 0;

        struCardInfo.dwCardRight = 0;

        byte[] strCardName = new byte[0];
        try {
            strCardName = name.getBytes("GBK");
        } catch (UnsupportedEncodingException e) {
            log.error("不支持的编码异常", e);
        }
        System.arraycopy(strCardName, 0, struCardInfo.byName, 0, strCardName.length);
        struCardInfo.write();
        Pointer pSendBufSet = struCardInfo.getPointer();

        if (!this.accessControl.getHCNetSDK().NET_DVR_SendRemoteConfig(lHandle, 0x3, pSendBufSet, struCardInfo.size())) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.error("ENUM_ACS_SEND_DATA失败，错误号：{}", iErr);
            return;
        }

        ThreadUtil.sleep(5000);

        if (!this.accessControl.getHCNetSDK().NET_DVR_StopRemoteConfig(lHandle)) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.error("断开长连接失败，错误号：{}", iErr);
            return;
        }
        log.info("断开长连接成功!");
    }

    @Override
    public void getFace(String cardNo) {
        int iErr = 0;
        HCNetSDK.NET_DVR_FACE_PARAM_COND mStruFaceInputParam = new HCNetSDK.NET_DVR_FACE_PARAM_COND();
        mStruFaceInputParam.dwSize = mStruFaceInputParam.size();
        //人脸关联的卡号
        mStruFaceInputParam.byCardNo = cardNo.getBytes();
        mStruFaceInputParam.byEnableCardReader[0] = 1;
        mStruFaceInputParam.dwFaceNum = 1;
        mStruFaceInputParam.byFaceID = 1;
        mStruFaceInputParam.write();

        Pointer lpInBuffer = mStruFaceInputParam.getPointer();
        Pointer pUserData = null;
        this.accessControl.setFRemoteCfgCallBackFaceGet(new FRemoteCfgCallBackFaceGet());

        NativeLong lHandle = this.accessControl.getHCNetSDK().NET_DVR_StartRemoteConfig(new NativeLong(this.accessControl.getUserId()),
                HCNetSDK.NET_DVR_GET_FACE_PARAM_CFG, lpInBuffer, mStruFaceInputParam.size(), this.accessControl.getFRemoteCfgCallBackFaceGet(), pUserData);
        if (stopRemoteConfig(lHandle)) {
            return;
        }
        log.info("断开长连接成功");
    }

    @Override
    public void setFace(String cardNo, String faceUrl) {
        int iErr = 0;
        //设置人脸参数
        HCNetSDK.NET_DVR_FACE_PARAM_COND mStruFaceSetParam = new HCNetSDK.NET_DVR_FACE_PARAM_COND();
        mStruFaceSetParam.dwSize = mStruFaceSetParam.size();
        //人脸关联的卡号
        mStruFaceSetParam.byCardNo = cardNo.getBytes();
        //人脸的读卡器是否有效，按数组表示，每位数组表示一个读卡器，数组取值：0-无效，1-有效
        mStruFaceSetParam.byEnableCardReader[0] = 1;
        // 设置或获取人脸数量，获取时置为0xffffffff表示获取所有人脸信息
        mStruFaceSetParam.dwFaceNum = 1;
        // 人脸数据类型：0-模板（默认），1-图片
        mStruFaceSetParam.byFaceID = 1;
        mStruFaceSetParam.write();

        Pointer lpInBuffer = mStruFaceSetParam.getPointer();

        Pointer pUserData = null;
        this.accessControl.setFRemoteCfgCallBackFaceGet(new FRemoteCfgCallBackFaceSet());

        NativeLong lHandle = this.accessControl.getHCNetSDK().NET_DVR_StartRemoteConfig(new NativeLong(this.accessControl.getUserId()),
                HCNetSDK.NET_DVR_SET_FACE_PARAM_CFG, lpInBuffer, mStruFaceSetParam.size(), this.accessControl.getFRemoteCfgCallBackFaceGet(), pUserData);
        if (lHandle.intValue() < 0) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("建立长连接失败，错误号：{}", iErr);
            return;
        }
        //卡参数
        HCNetSDK.NET_DVR_FACE_PARAM_CFG struFaceInfo = new HCNetSDK.NET_DVR_FACE_PARAM_CFG();
        struFaceInfo.read();
        struFaceInfo.dwSize = struFaceInfo.size();
        struFaceInfo.byCardNo = cardNo.getBytes();
        //需要下发人脸的读卡器，按数组表示，每位数组表示一个读卡器，数组取值：0-不下发该读卡器，1-下发到该读卡器
        struFaceInfo.byEnableCardReader[0] = 1;
        //人脸ID编号，有效取值范围：1~2
        struFaceInfo.byFaceID = 1;
        //人脸数据类型：0- 模板（默认），1- 图片
        struFaceInfo.byFaceDataType = 1;

        byte[] input = HttpRequest.get(faceUrl).execute().bodyBytes();
        if (input.length < 1) {
            log.info("input file dataSize < 1");
            return;
        }
        HCNetSDK.BYTE_ARRAY ptrpicByte = new HCNetSDK.BYTE_ARRAY(input.length);
        System.arraycopy(input, 0, ptrpicByte.byValue, 0, input.length);
        ptrpicByte.write();

        struFaceInfo.dwFaceLen = input.length;
        struFaceInfo.pFaceBuffer = ptrpicByte.getPointer();

        struFaceInfo.write();
        Pointer pSendBufSet = struFaceInfo.getPointer();

        //ENUM_ACS_INTELLIGENT_IDENTITY_DATA = 9,  //智能身份识别终端数据类型，下发人脸图片数据
        if (!this.accessControl.getHCNetSDK().NET_DVR_SendRemoteConfig(lHandle, 0x9, pSendBufSet, struFaceInfo.size())) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("NET_DVR_SendRemoteConfig失败，错误号：{}", iErr);
            return;
        }

        if (stopRemoteConfig(lHandle)) {
            return;
        }
        log.info("断开长连接成功");
    }

    @Override
    public boolean delFace(String cardNo) {
        int iErr = 0;
        //删除人脸数据
        HCNetSDK.NET_DVR_FACE_PARAM_CTRL mStruFaceDel = new HCNetSDK.NET_DVR_FACE_PARAM_CTRL();
        mStruFaceDel.dwSize = mStruFaceDel.size();
        //删除方式：0- 按卡号方式删除，1- 按读卡器删除
        mStruFaceDel.byMode = 0;

        mStruFaceDel.struProcessMode.setType(HCNetSDK.NET_DVR_FACE_PARAM_BYCARD.class);
        //需要删除人脸关联的卡号
        mStruFaceDel.struProcessMode.struByCard.byCardNo = cardNo.getBytes();
        //读卡器
        mStruFaceDel.struProcessMode.struByCard.byEnableCardReader[0] = 1;
        //人脸ID
        mStruFaceDel.struProcessMode.struByCard.byFaceID[0] = 1;
        mStruFaceDel.write();

        Pointer lpInBuffer = mStruFaceDel.getPointer();

        boolean lRemoteCtrl = this.accessControl.getHCNetSDK().NET_DVR_RemoteControl(new NativeLong(this.accessControl.getUserId()), HCNetSDK.NET_DVR_DEL_FACE_PARAM_CFG, lpInBuffer, mStruFaceDel.size());
        if (!lRemoteCtrl) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("NET_DVR_DEL_FACE_PARAM_CFG删除人脸图片失败，错误号：{}", iErr);
        }
        return lRemoteCtrl;
    }

    @Override
    public boolean setPlan(HCNetSDK.NET_DVR_WEEK_PLAN_COND struWeekPlanCondParam, HCNetSDK.NET_DVR_WEEK_PLAN_CFG struWeekPlanCfgParam, HCNetSDK.NET_DVR_PLAN_TEMPLATE struPlanTemParam) throws UnsupportedEncodingException {
        int iErr = 0;
        HCNetSDK.NET_DVR_WEEK_PLAN_COND struWeekPlanCond = new HCNetSDK.NET_DVR_WEEK_PLAN_COND();
        struWeekPlanCond.dwSize = struWeekPlanCond.size();
        struWeekPlanCond.dwWeekPlanNumber = struWeekPlanCondParam.dwWeekPlanNumber;
        struWeekPlanCond.wLocalControllerID = struWeekPlanCondParam.wLocalControllerID;
        HCNetSDK.NET_DVR_WEEK_PLAN_CFG struWeekPlanCfg = new HCNetSDK.NET_DVR_WEEK_PLAN_CFG();
        IntByReference pInt = new IntByReference(0);
        Pointer lpStatusList = pInt.getPointer();
        struWeekPlanCond.write();
        struWeekPlanCfg.write();
        Pointer lpCond = struWeekPlanCond.getPointer();
        Pointer lpInbuferCfg = struWeekPlanCfg.getPointer();
        if (!this.accessControl.getHCNetSDK().NET_DVR_GetDeviceConfig(new NativeLong(this.accessControl.getUserId()),
                HCNetSDK.NET_DVR_GET_CARD_RIGHT_WEEK_PLAN_V50, 1, lpCond, struWeekPlanCond.size(), lpStatusList, lpInbuferCfg, struWeekPlanCfg.size())) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("NET_DVR_GET_CARD_RIGHT_WEEK_PLAN_V50失败，错误号：" + iErr);
            return false;
        }
        struWeekPlanCfg.read();
        // 时间初始化
        for (int i = 0; i < 7; i++) {
            for (int j = 0; j < 8; j++) {
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].byEnable = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.byHour = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.byMinute = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.bySecond = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.byHour = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.byMinute = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.bySecond = 0;
            }
        }
        struWeekPlanCfg.struPlanCfg = struWeekPlanCfgParam.struPlanCfg;
//        for (int i = 0; i < 7; i++) {
//            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].byEnable = 1;
//
//            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struBeginTime.byHour = 0;
//            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struBeginTime.byMinute = 0;
//            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struBeginTime.bySecond = 0;
//            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struEndTime.byHour = 23;
//            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struEndTime.byMinute = 59;
//            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struEndTime.bySecond = 59;
//        }
        struWeekPlanCfg.write();
        if (!this.accessControl.getHCNetSDK().NET_DVR_SetDeviceConfig(new NativeLong(this.accessControl.getUserId()), HCNetSDK.NET_DVR_SET_CARD_RIGHT_WEEK_PLAN_V50, 1, lpCond, struWeekPlanCond.size(), lpStatusList, lpInbuferCfg, struWeekPlanCfg.size())) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("NET_DVR_SET_CARD_RIGHT_WEEK_PLAN_V50失败，错误号：" + iErr);
            return false;
        }
        //设置卡权限计划模板，发卡时关联该模板即可
        HCNetSDK.NET_DVR_PLAN_TEMPLATE struPlanTem = new HCNetSDK.NET_DVR_PLAN_TEMPLATE();
        struPlanTem.dwSize = struPlanTem.size();
        //是否使能：0- 否，1- 是
        struPlanTem.byEnable = 1;
        System.arraycopy(struPlanTemParam.byTemplateName, 0, struPlanTem.byTemplateName, 0, struPlanTemParam.byTemplateName.length);
        //周计划编号 1
        struPlanTem.dwWeekPlanNo = struPlanTemParam.dwWeekPlanNo;
        //假日组编号 1，一个计划模板最多可关联 16 个假日组
//        struPlanTem.dwHolidayGroupNo[0] = 1;
//        struPlanTem.dwHolidayGroupNo[1] = 2;
        struPlanTem.write();
        Pointer lpInBuffer = struPlanTem.getPointer();
        boolean result = this.accessControl.getHCNetSDK().NET_DVR_SetDVRConfig(new NativeLong(this.accessControl.getUserId()), HCNetSDK.NET_DVR_SET_CARD_RIGHT_PLAN_TEMPLATE, new NativeLong(1), lpInBuffer, struPlanTem.size());
        if (!result) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("设置卡权限计划模版失败，错误号：" + iErr);
            return false;
        }
        struPlanTem.read();
        log.info("NET_DVR_SET_CARD_RIGHT_WEEK_PLAN_V50成功！");
        return true;
    }

    @Override
    public boolean setPlan(Plan plan) throws UnsupportedEncodingException {
        return setPlan(plan.getWeekPlanCond(), plan.getWeekPlanCfg(), plan.getPlanTemplate());
    }

    @Override
    public boolean setPlan() throws UnsupportedEncodingException {
        int iErr;
        HCNetSDK.NET_DVR_WEEK_PLAN_COND struWeekPlanCond = new HCNetSDK.NET_DVR_WEEK_PLAN_COND();
        struWeekPlanCond.dwSize = struWeekPlanCond.size();
        struWeekPlanCond.dwWeekPlanNumber = 2;
        struWeekPlanCond.wLocalControllerID = 0;
        HCNetSDK.NET_DVR_WEEK_PLAN_CFG struWeekPlanCfg = new HCNetSDK.NET_DVR_WEEK_PLAN_CFG();
        IntByReference pInt = new IntByReference(0);
        Pointer lpStatusList = pInt.getPointer();
        struWeekPlanCond.write();
        struWeekPlanCfg.write();
        Pointer lpCond = struWeekPlanCond.getPointer();
        Pointer lpInbuferCfg = struWeekPlanCfg.getPointer();
        if (!accessControl.getHCNetSDK().NET_DVR_GetDeviceConfig(new NativeLong(accessControl.getUserId()), HCNetSDK.NET_DVR_GET_CARD_RIGHT_WEEK_PLAN_V50, 1, lpCond, struWeekPlanCond.size(), lpStatusList, lpInbuferCfg, struWeekPlanCfg.size())) {
            iErr = accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("NET_DVR_GET_CARD_RIGHT_WEEK_PLAN_V50失败，错误号：" + iErr);
            return false;
        }
        struWeekPlanCfg.read();
        for (int i = 0; i < 7; i++) {
            for (int j = 0; j < 8; j++) {
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].byEnable = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.byHour = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.byMinute = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.bySecond = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.byHour = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.byMinute = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.bySecond = 0;
            }
        }
        for (int i = 0; i < 7; i++) {
            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].byEnable = 1;
            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struBeginTime.byHour = 0;
            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struBeginTime.byMinute = 0;
            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struBeginTime.bySecond = 0;
            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struEndTime.byHour = 23;
            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struEndTime.byMinute = 59;
            struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[0].struTimeSegment.struEndTime.bySecond = 59;
        }
        struWeekPlanCfg.write();
        if (!accessControl.getHCNetSDK().NET_DVR_SetDeviceConfig(new NativeLong(accessControl.getUserId()), HCNetSDK.NET_DVR_SET_CARD_RIGHT_WEEK_PLAN_V50, 1, lpCond, struWeekPlanCond.size(), lpStatusList, lpInbuferCfg, struWeekPlanCfg.size())) {
            iErr = accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("NET_DVR_SET_CARD_RIGHT_WEEK_PLAN_V50失败，错误号：" + iErr);
            return false;
        }
        //设置卡权限计划模板，发卡时关联该模板即可
        HCNetSDK.NET_DVR_PLAN_TEMPLATE struPlanTem = new HCNetSDK.NET_DVR_PLAN_TEMPLATE();
        struPlanTem.dwSize = struPlanTem.size();
        //是否使能：0- 否，1- 是
        struPlanTem.byEnable = 1;
        byte[] templateName = "通用卡权限计划模版".getBytes("GBK");
        System.arraycopy(templateName, 0, struPlanTem.byTemplateName, 0, templateName.length);
        //周计划编号 1
        struPlanTem.dwWeekPlanNo = 1;
        struPlanTem.write();
        Pointer lpInBuffer = struPlanTem.getPointer();
        boolean result = accessControl.getHCNetSDK().NET_DVR_SetDVRConfig(new NativeLong(accessControl.getUserId()), HCNetSDK.NET_DVR_SET_CARD_RIGHT_PLAN_TEMPLATE, new NativeLong(1), lpInBuffer, struPlanTem.size());
        if (!result) {
            iErr = accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("设置卡权限计划模版失败，错误号：" + iErr);
            return false;
        }
        struPlanTem.read();
        log.info("NET_DVR_SET_CARD_RIGHT_WEEK_PLAN_V50成功！");
        return true;
    }

    @Override
    public boolean setupAlarmChan() {
        if (this.accessControl.getUserId() == -1) {
            log.info("请先注册");
            return false;
        }
        //尚未布防,需要布防
        if (this.accessControl.getLAlarmHandle() < 0) {
            if (null == this.accessControl.getFMSFCallBackV31()) {
                this.accessControl.setFMSFCallBackV31(new FMSGCallBackV31());
                Pointer pUser = null;
                if (!this.accessControl.getHCNetSDK().NET_DVR_SetDVRMessageCallBack_V31(this.accessControl.getFMSFCallBackV31(), pUser)) {
                    log.info("设置回调函数失败!");
                    return false;
                }
            }
            HCNetSDK.NET_DVR_SETUPALARM_PARAM mStrAlarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM();
            mStrAlarmInfo.dwSize = mStrAlarmInfo.size();
            mStrAlarmInfo.byLevel = 1;
            mStrAlarmInfo.byAlarmInfoType = 1;
            mStrAlarmInfo.write();
            NativeLong lAlarmHandle = this.accessControl.getHCNetSDK().NET_DVR_SetupAlarmChan_V41(new NativeLong(this.accessControl.getUserId()), mStrAlarmInfo);
            if (lAlarmHandle.intValue() == -1) {
                log.info("布防失败");
                return false;
            }
            this.accessControl.setLAlarmHandle(lAlarmHandle.longValue());
            log.info("布放成功");
        } else {
            log.info("已经布防，无需再次布防");
        }
        return true;
    }

    @Override
    public boolean closeAlarmChan() {
        //报警撤防
        if (this.accessControl.getLAlarmHandle() > -1) {
            if (!this.accessControl.getHCNetSDK().NET_DVR_CloseAlarmChan_V30(new NativeLong(this.accessControl.getLAlarmHandle()))) {
                log.info("撤防失败");
                return false;
            }
            log.info("撤防成功");
            this.accessControl.setLAlarmHandle(-1);
        } else {
            log.info("尚未布防，无需撤防");
        }
        return true;
    }

    private boolean stopRemoteConfig(NativeLong lHandle) {
        int iErr;
        if (lHandle.intValue() < 0) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("建立长连接失败，错误号：{}", iErr);
            return true;
        }

        ThreadUtil.sleep(1000);

        if (!this.accessControl.getHCNetSDK().NET_DVR_StopRemoteConfig(lHandle)) {
            iErr = this.accessControl.getHCNetSDK().NET_DVR_GetLastError();
            log.info("断开长连接失败，错误号：{}", iErr);
            return true;
        }
        return false;
    }

    public static void main(String[] args) throws MalformedURLException, UnsupportedEncodingException {
        AccessControlServiceImpl deviceService = new AccessControlServiceImpl();
//        DeviceService deviceService2 = new AccessControlServiceImpl();
        System.out.println(deviceService.login("10.0.0.223", 8000, "admin", "hik12345"));
//        System.out.println(deviceService2.login("10.0.0.101", 8000, "admin", "qwer1234"));
//        System.out.println(deviceService.getNetwork().toString());
//        deviceService.getAccessControl().getmStrNetConfig().wAlarmHostIpPort = 7200;
//        deviceService.getAccessControl().getmStrNetConfig().struAlarmHostIpAddr.sIpV4 = "10.0.0.145".getBytes();
//        log.info("设置网络信息：{}",deviceService.setNetwork(deviceService.getAccessControl().getmStrNetConfig()));
//        deviceService.getAllCard();
//        deviceService.getCard("111013");
//        deviceService.getFace("111013");
//        deviceService.setFace("111013", "https://img.aiairy.com/IDCard/微信图片_20190408162833.jpg");
//        deviceService.setupAlarmChan();
//        deviceService2.setupAlarmChan();
//
//        deviceService.closeAlarmChan();
//        deviceService2.closeAlarmChan();
//        String p = "{\"autoRead\":true,\"autoWrite\":true,\"byEnable\":0,\"byRes1\":\"AAAA\",\"byRes2\":\"AAAAAAAAAAAAAAAAAAAAAA==\",\"dwSize\":920,\"pointer\":{\"size\":920,\"valid\":true},\"struPlanCfg\":[{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":912,\"valid\":true},\"struPlanCfgDay\":[{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":1,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":912,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":904,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":904,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":23,\"byMinute\":59,\"byRes\":0,\"bySecond\":59,\"pointer\":{\"size\":900,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":896,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":888,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":888,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":884,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":880,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":872,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":872,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":868,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":864,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":856,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":856,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":852,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":848,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":840,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":840,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":836,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":832,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":824,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":824,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":820,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":816,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":808,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":808,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":804,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":800,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":792,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":792,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":788,\"valid\":true}}}}]},{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":784,\"valid\":true},\"struPlanCfgDay\":[{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":1,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":784,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":776,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":776,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":23,\"byMinute\":59,\"byRes\":0,\"bySecond\":59,\"pointer\":{\"size\":772,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":768,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":760,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":760,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":756,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":752,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":744,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":744,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":740,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":736,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":728,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":728,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":724,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":720,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":712,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":712,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":708,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":704,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":696,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":696,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":692,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":688,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":680,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":680,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":676,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":672,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":664,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":664,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":660,\"valid\":true}}}}]},{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":656,\"valid\":true},\"struPlanCfgDay\":[{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":1,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":656,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":648,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":648,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":23,\"byMinute\":59,\"byRes\":0,\"bySecond\":59,\"pointer\":{\"size\":644,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":640,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":632,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":632,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":628,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":624,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":616,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":616,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":612,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":608,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":600,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":600,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":596,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":592,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":584,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":584,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":580,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":576,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":568,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":568,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":564,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":560,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":552,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":552,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":548,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":544,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":536,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":536,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":532,\"valid\":true}}}}]},{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":528,\"valid\":true},\"struPlanCfgDay\":[{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":1,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":528,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":520,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":520,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":23,\"byMinute\":59,\"byRes\":0,\"bySecond\":59,\"pointer\":{\"size\":516,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":512,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":504,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":504,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":500,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":496,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":488,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":488,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":484,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":480,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":472,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":472,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":468,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":464,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":456,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":456,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":452,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":448,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":440,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":440,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":436,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":432,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":424,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":424,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":420,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":416,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":408,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":408,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":404,\"valid\":true}}}}]},{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":400,\"valid\":true},\"struPlanCfgDay\":[{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":1,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":400,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":392,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":392,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":23,\"byMinute\":59,\"byRes\":0,\"bySecond\":59,\"pointer\":{\"size\":388,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":384,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":376,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":376,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":372,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":368,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":360,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":360,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":356,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":352,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":344,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":344,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":340,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":336,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":328,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":328,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":324,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":320,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":312,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":312,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":308,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":304,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":296,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":296,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":292,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":288,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":280,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":280,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":276,\"valid\":true}}}}]},{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":272,\"valid\":true},\"struPlanCfgDay\":[{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":1,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":272,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":264,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":264,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":23,\"byMinute\":59,\"byRes\":0,\"bySecond\":59,\"pointer\":{\"size\":260,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":256,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":248,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":248,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":244,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":240,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":232,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":232,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":228,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":224,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":216,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":216,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":212,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":208,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":200,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":200,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":196,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":192,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":184,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":184,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":180,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":176,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":168,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":168,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":164,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":160,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":152,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":152,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":148,\"valid\":true}}}}]},{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":144,\"valid\":true},\"struPlanCfgDay\":[{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":1,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":144,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":136,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":136,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":23,\"byMinute\":59,\"byRes\":0,\"bySecond\":59,\"pointer\":{\"size\":132,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":128,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":120,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":120,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":116,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":112,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":104,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":104,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":100,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":96,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":88,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":88,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":84,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":80,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":72,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":72,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":68,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":64,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":56,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":56,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":52,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":48,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":40,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":40,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":36,\"valid\":true}}}},{\"autoRead\":true,\"autoWrite\":true,\"byDoorStatus\":0,\"byEnable\":0,\"byRes\":\"AAAAAAA=\",\"byVerifyMode\":0,\"pointer\":{\"size\":32,\"valid\":true},\"struTimeSegment\":{\"autoRead\":true,\"autoWrite\":true,\"pointer\":{\"size\":24,\"valid\":true},\"struBeginTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":24,\"valid\":true}},\"struEndTime\":{\"autoRead\":true,\"autoWrite\":true,\"byHour\":0,\"byMinute\":0,\"byRes\":0,\"bySecond\":0,\"pointer\":{\"size\":20,\"valid\":true}}}}]}]}";
//        HCNetSDK.NET_DVR_WEEK_PLAN_CFG weekPlanCfg = JSON.parseObject(p, HCNetSDK.NET_DVR_WEEK_PLAN_CFG.class);
//
//        HCNetSDK.NET_DVR_WEEK_PLAN_COND struWeekPlanCond = new HCNetSDK.NET_DVR_WEEK_PLAN_COND();
//        struWeekPlanCond.dwWeekPlanNumber = 2;
//        struWeekPlanCond.wLocalControllerID = 0;
//        //设置卡权限计划模板，发卡时关联该模板即可
//        HCNetSDK.NET_DVR_PLAN_TEMPLATE struPlanTem = new HCNetSDK.NET_DVR_PLAN_TEMPLATE();
//        //是否使能：0- 否，1- 是
//        struPlanTem.byEnable = 1;
//        byte[] templateName = "通用卡权限计划模版1111".getBytes("GBK");
//
//        System.arraycopy(templateName, 0, struPlanTem.byTemplateName, 0, templateName.length);
//        //周计划编号 1
//        struPlanTem.dwWeekPlanNo = 1;
//
//        deviceService.setPlan(struWeekPlanCond, weekPlanCfg, struPlanTem);
//        deviceService.setPlan();
        System.out.println(JSON.toJSONString(deviceService.getDeviceConfig()));

    }

}
